<include file="__THEME__/header" />
<link href="../Public/css/tree.css" rel="stylesheet" type="text/css" />
<link href="../Public/css/purview.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
var pageType = '';
function changeType(type){
    pageType = type;
	$("tr[id*='pageType_']").each(function(i,n){
		$(this).css('display', 'none');
	});
	
	if(type=='link') $("#pageType_link1").css('display', '');
	else             $("#pageType_leaf2").css('display', '');
}

function uploadTemp(type){
	var url = "{:U('portal/Page/uploadTemp','channelId='.$channelId)}"+'&type='+type;
	$.tbox.popup(url, '上传文件');
}

function openWin(){
	var url = "{:U('portal/Index/index', array('channel'=>$channelInfo[domain], 'page'=>$page[domain]))}";
	
	window.open(url)
}

function openWinDiy(){
	var url = "{:U('portal/Diy/index', array('channel'=>$channelInfo[domain], 'page'=>$page[domain], 'diy'=>'1'))}";	
	window.open(url)
}

$(function () { 	
	var isEidt = "{$page.id}";
	if(isEidt!=''){
		//$("#domain").html("{:SITE_URL}/{$channel.domain}/{$page.pageTemp}.html");	
		pageType = '{$page.pageType}';		

		$("input[name='pageType']").val([pageType]);
		$("#pageTemp").attr("value",'{$page.pageTemp}');
		$("input[name='jumpTarget']").val(['{$page.jumpTarget}']);
		$("#category").attr("value",'{$page.category}');
		$("#listTemp").attr("value",'{$page.listTemp}');
		$("#detailTemp").attr("value",'{$page.detailTemp}');
		$("#purview").attr("value",'{$page.purview}');	
		$("#categoryId").attr("value",'{$page.categoryId}');	
	}
	
    if(pageType==''){
		//var pageTemp = $("#pageTemp").val();
		//$("#domain").html("{:SITE_URL}/{$channel.domain}/"+pageTemp+".html");
		pageType = 'leaf';
		$("input[name='pageType']").val([pageType]);
	}
	changeType(pageType);	
});
</script>
<include file="../Public/myChannel" />
<div class="contents"> 

<include file="../Public/admin_tree" />

  <div class="content_pur_left R">
    <div style="width:100%;" class="L">
      <div><include file="../Public/nav_head" /></div>
      <form id="form1" name="form1" method="post" action="{:U('portal/Page/doDealPage','channelId='.$channelId)}">
        <table width="97%" border="0" cellpadding="0" cellspacing="3" align="left" class="mt10">
		  <tr>
            <td align="right">所在分层：</td>
            <td height="30" align="left"><label>
              <select name="categoryId" id="categoryId">
			  <php>if($userLevel>1){</php><option value="">请选择</option><php>}</php>
               <php>foreach($cateArr as $key=>$vo){</php>
				<option value="{$key}">{$vo}</option>
                <php>}</php>
              </select>
            </label></td>
          </tr>
          <tr>
            <td align="right">页面类型：</td>
            <td height="30" align="left"><label>
                <input type="radio" name="pageType" value="leaf" onclick="changeType('leaf')"/>
                单页面</label><label>
                <input type="radio" name="pageType" value="list" onclick="changeType('list')"/>
                文章分类</label><label>
                <input type="radio" name="pageType" value="link" onclick="changeType('link')"/>
                跳转链接 </label></td>
          </tr>		  
          <tr>
            <td width="90" align="right">页面名称：</td>
            <td height="30" align="left"><input class="in_put" style="width:200px" name="name" type="text" id="name" value="{$page.name}" maxlength="30" /></td>
          </tr>
          <!--          <tr id="pageType_leaf1" style="display:none">
            <td align="right">页面模板：</td>
            <td height="30" align="left"><select name="pageTemp" id="pageTemp">
                <option value="default">默认模板</option>
                <volist name='pageTemp' id='vo'>
                  <option value="{$vo}">{$vo}</option>
                </volist>
              </select>
              <a href="javascript:void(0)" onclick="uploadTemp('pageTemp')">上传新模板</a></td>
          </tr>-->
          <tr id="pageType_leaf2" style="display:none">
            <td align="right">访问链接：</td>
            <td height="30" align="left"> {:SITE_URL}/{$channelInfo.domain}/
              <input class="in_put" style="width:50px" name="domain" type="text" id="domain" value="{$page.domain}" maxlength="30" /> .html&nbsp;注：由字母，数字和下划线组成，而且第一个字符必须是字母</td>
          </tr>
          <tr id="pageType_link1" style="display:none">
            <td align="right">跳转链接：</td>
            <td height="30" align="left"><input name="jumpURL" type="text" id="jumpURL" value="{$page.jumpURL}" />
              <input type="checkbox" name="jumpTarget" id="jumpTarget" value="_blank" />
              新窗口</td>
          </tr>
          <!--          <tr id="pageType_list1" style="display:none">
            <td align="right">文章分类：</td>
            <td height="30" align="left"><select name="category" id="category">
                <option value="新闻">新闻</option>
                <option value="公告">公告</option>
              </select></td>
          </tr>
          <tr id="pageType_list2" style="display:none">
            <td align="right">列表页模板：</td>
            <td height="30" align="left"><select name="listTemp" id="listTemp">
                <option value="default">默认模板</option>
                <volist name='listTemp' id='vo'>
                  <option value="{$vo}">{$vo}</option>
                </volist>
              </select>
              <a href="javascript:void(0)" onclick="uploadTemp('listTemp')">上传新模板</a></td>
          </tr>
          <tr id="pageType_list3" style="display:none">
            <td align="right">内容页模板：</td>
            <td height="30" align="left"><select name="detailTemp" id="detailTemp">
                <option value="default">默认模板</option>
                <volist name='detailTemp' id='vo'>
                  <option value="{$vo}">{$vo}</option>
                </volist>
              </select>
              <a href="javascript:void(0)" onclick="uploadTemp('detailTemp')">上传新模板</a></td>
          </tr>
          <tr>
            <td align="right">编辑权限：</td>
            <td height="30" align="left"><select name="purview" id="purview" class="in_put_01">
                <option value="0">所有管理员</option>
                <volist name='manager' id='vo'>
                <option value="{$vo}">{$vo|getUserName}</option>
                </volist>
              </select>
              <a class="ml5" href="{:U('portal/Purview/index','channelId='.$channelId)}">增加管理员</a></td>
          </tr>-->
          <tr>
            <td>&nbsp;</td>
            <td height="30" align="left"><input type="hidden" name="pageId" id="pageId" value="{$page.id}" />
              <input type="hidden" name="channelId" id="channelId" value="{$channelId}" />
              <input type="hidden" name="channelDomain" id="channelDomain" value="{$channelInfo.domain}" />
              <input type="button" class="btn_sea" name="button" id="button" value="提交" onclick="checkForm()"/></td>
          </tr>
        </table>
      </form>
    </div>
  </div>
</div>
<include file="__THEME__/footer" />
<script type="text/javascript">
function checkForm(){
    if(pageType=='link'){
	   var domain = $("#jumpURL").val();
		if(domain=='')
		{
			 alert("跳转链接不能为空");
			 return false;
		}	   
		$("#form1").submit();
		return true;	   
	}
	
	var domain = $("#domain").val();
	
	//判断第一字母是否为字母
	var str = /[_a-zA-Z]/;	
	var a = domain.substring(0,1);
	if(!str.test(a))
	{
	     alert("访问链接第一字母必须是字母");
		 return false;
	}
	
	//只允许字母，数字和下划线
	var str = /^[a-zA-Z0-9_]{1,}$/;
	if(!str.test(domain))
	{
	     alert("访问链接只能由字母，数字和下划线组成");
		 return false;
	}
	
	//不能重名
	var pageId = "{$page.id}";
	if(pageId != ''){
		$("#form1").submit();
		return true;
	}
	var url = "{:U('portal/Page/checkDomain')}";
	var channelId = "{$channelId}";
	$.post(url, {channelId:channelId, domain:domain}, function(res){
		if(res==1){
			 alert("访问链接已经存在，请重命名");
			 return false;			
		}else{
			$("#form1").submit();
		}
	});		
}
</script>